package com.zxdemo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.shiro.crypto.hash.Sha256Hash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zxdemo.jpa.model.Menu;
import com.zxdemo.service.MenuService;
import com.zxdemo.service.UserRoleService;
import com.zxdemo.service.UserService;

@RestController
public class TestController {
			protected Logger logger = LoggerFactory.getLogger(TestController.class);		
			
			@SuppressWarnings("unused")
			@Autowired
			private UserService userService;
			@Autowired
			private UserRoleService userRoleService;
			@Autowired
			private MenuService menuService;

			@RequestMapping("/hello")
			public String Hello(){
				
				String hashString=(new Sha256Hash("123456")).toHex();
				return hashString;
			}
			
			@RequestMapping("/role")
			public List<Long> Hello2(){
				Long userId=(long) 1;
				return userRoleService.queryRoleIdList(userId);
			}
			
			@RequestMapping("/update")
			public String update(){
				
				Long userId=(long) 1;
				Long role1=(long) 3;
				Long role2=(long) 4;
				Long role3=(long) 5;
				List<Long> roles=new ArrayList<Long>();
				roles.add(role1);
				roles.add(role2);
				roles.add(role3);
				try {
					userRoleService.saveOrUpdate(userId, roles);
				} catch (Exception e) {
					// TODO: handle exception
					System.out.println(e);
				}
				
			    return "更新成功";
			}
			@RequestMapping("/menu")
			public List<Menu> Menu1(){
				System.out.println("我进啦");
				List<Menu> list =menuService.getUserMenuList(2L);
				
				
				return list;
			}
			@RequestMapping(value="/hello19")
			public String Hello19(){
				return "你好";
			}
			
			
			@RequestMapping("/getCat")
			public Cat getCat(){
				Cat cat=new Cat();
				cat.setId(1);
				cat.setName("xiaohua2");
				cat.setCreateTime(new Date());
				return cat;
			}
}
